package com.qiaoyanqing.textdemoqyq7.Activities;


import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.qiaoyanqing.textdemoqyq7.Adapters.WelcomeVPAdapter;
import com.qiaoyanqing.textdemoqyq7.Fragments.WelconmeFragment;
import com.qiaoyanqing.textdemoqyq7.R;

import java.util.ArrayList;
import java.util.List;

public class FirstActivity extends AppCompatActivity {
    private ViewPager mViewPager;
    private List<Fragment>mData=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        mViewPager= (ViewPager) findViewById(R.id.viewpager);

        initData();

        initViewpager();

    }

    private void initViewpager() {
        mViewPager.setAdapter(new WelcomeVPAdapter(getSupportFragmentManager(),mData));

    }

    private void initData() {
       mData.add(getWelcomeFragment("slide1"));
       mData.add(getWelcomeFragment("slide2"));
       mData.add(getWelcomeFragment("slide3"));

    }

    private Fragment getWelcomeFragment(String index) {
        WelconmeFragment fragment=new WelconmeFragment();
        Bundle bundle=new Bundle();
        bundle.putString("index",index);
        fragment.setArguments(bundle);

        return fragment;
    }
}
